package com.gqzmy.springboot3.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gqzmy.springboot3.entity.Role;
import com.gqzmy.springboot3.mapper.RoleMapper;
import com.gqzmy.springboot3.vo.RoleQuery;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 周小哥  gqzmy@163.com 2023/4/20 17:10
 */

@Service
public class RoleServiceImpl implements RoleService {

    @Resource
    private RoleMapper roleMapper;

    @Override
    public Role insertRole(Role role) {
        if (1 == roleMapper.insertRole(role)) {
            return roleMapper.getById(role.getId());
        }
        throw new RuntimeException();
    }

    @Override
    public boolean deleteById(String id) {
        return 1 == roleMapper.deleteById(id);
    }

    @Override
    public Role getById(String id) {
        return roleMapper.getById(id);
    }

    @Override
    public PageInfo<Role> getRolePageInfo(RoleQuery roleQuery) {
        PageHelper.startPage(roleQuery.getPagingBase().getPageNum(), roleQuery.getPagingBase().getPageSize());
        List<Role> roleList = roleMapper.getRoleList(roleQuery);
        return new PageInfo<>(roleList);
    }
}
